const Base = require('./base.js');

module.exports = class extends Base {
	constructor(ctx) {
		super(ctx);
		this.tbksetup = this.model("taoke/setup");
		this.setup = think.model('system/setup');

	}
	async indexAction() {
		if(this.isGet) {
			let setup = await this.tbksetup.where({
				group: 1
			}).select();

			this.assign("setup", this.tbksetup.extra(setup));
			return this.display();
		}

		let posts = this.post();
		console.log(posts);
		let row = await this.tbksetup.transaction(async() => {
			let row = 0;
			for(let i in posts) {
				let update = await this.tbksetup.where({
					code: i
				}).update({
					value: posts[i]
				});
				if(update == 1) {
					row++;
				}

			};
			return row;
		});
		const setup = await this.setup.selectAll();
		think.config('setup', setup);
		return this.success("修改成功");

	}

};